function link(url, data, rep, method, fail) {
  var access_token = wx.getStorageSync("token");
  if (data == undefined) {
    data = {}
  }
  if (!method) {
    method = "POST"
  }
  // wx.showLoading({
  //   title: '加载中',
  // })
  wx.request({
    url: url, //仅为示例，并非真实的接口地址
    method: method,
    data: data,
    header: {
      'content-type': 'application/json',
      'Authorization': access_token,
    },
    success: function(res) {
      wx.hideLoading()
      try {
        rep(res);
      } catch (err) {
        console.log(err)
        wx.showModal({
          title: '温馨提示',
          content: '登陆失效，请重新登录',
          success(res) {
            if (res.confirm) {
              wx.clearStorageSync()
              wx.reLaunch({
                url: '/pages/login/login',
              })
            }
          }
        })
      }
    },
    fail: function(res) {
      wx.hideLoading();
      console.log(res)
      fail(res);
      console.log("检测到网络失败");
    },
  })
}

function toast(title) {
  wx.showToast({
    title: title,
    icon: 'none'
  })
}
//setTimeout方法
function outTime(time, fun) {
  setTimeout(() => {
    fun()
  }, time)
}

function toalert(title, t, imgtype) {
  console.log(title);
  var errimgsrc = '';

  if (t == undefined) {
    t = 3000;
  }
  if (imgtype == undefined) {
    errimgsrc = '/images/gantaohao.png';
  }
  wx.showToast({
    title: title,
    icon: 'success',
    image: errimgsrc,
    duration: t
  })
}

function timeout() {}
module.exports.link = link
module.exports.toast = toast
module.exports.toalert = toalert
module.exports.outTime = outTime